package tw.com.hitevision.whiteboard.android.state;


import android.content.Context;

import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.core.content.ContextCompat;

import tw.com.hitevision.whiteboard.android.R;
import tw.com.hitevision.whiteboard.android.render.Autoshape;

public class AutoshapeProperty {

    private Color color;
    private Type type;
    private boolean fill;

    public AutoshapeProperty(Type type, Color color) {
        this.type = type;
        this.color = color;
    }

    public void setFill(boolean b) {
        fill = b;
    }

    public boolean getFill() {
        return fill;
    }

    public void setColor(Color c) {
        color = c;
    }

    public Color getColor() {
        return color;
    }

    public void setType(Type t) {
        type = t;
    }

    public Type getType() {
        return type;
    }

    public enum Color {
        BLACK, WHITE, RED, YELLOW, GREEN, BLUE, VERMILION, YELLOW_SOFT, BLUE_SOFT,PINK,  GREEN_SOFT
    }

    public enum Type {
        ARROW, CIRCLE, LINE, OVAL, REGULAR_TRIANGLE, RIGHT_TRIANGLE, SQUARE, STAR
    }

    @ColorRes
    public int getColorRes() {
        switch (color) {
            case BLACK:
                return R.color.pen_black;
            case WHITE:
                return R.color.pen_white;
            case RED:
                return R.color.pen_red;
            case YELLOW:
                return R.color.pen_pure_yellow;
            case GREEN:
                return R.color.pen_green;
            case BLUE:
                return R.color.pen_blue;
            case BLUE_SOFT:
                return R.color.pen_soft_blue;
            case PINK:
                return R.color.pen_pink;
            case VERMILION:
                return R.color.pen_vermilion;
            case GREEN_SOFT:
                return R.color.pen_soft_green;
            case YELLOW_SOFT:
                return R.color.pen_soft_yellow;
//            case STICKY_BLUE:
//                return R.color.sticky_note_blue;
//            case STICKY_PINK:
//                return R.color.sticky_note_pink;
//            case STICKY_GREEN:
//                return R.color.sticky_note_green;
//            case STICKY_WHITE:
//                return R.color.sticky_note_white;
//            case STICKY_PURPLE:
//                return R.color.sticky_note_purple;
//            case STICKY_YELLOW:
//                return R.color.sticky_note_yellow;
            default:
                return 0;
        }
    }

    @DrawableRes
    public int getTypeDrawableRes() {
        switch (type) {
            case ARROW:
                return R.drawable.ic_autoshape_arrow_big;
            case CIRCLE:
                return R.drawable.ic_autoshape_circle_big;
            case LINE:
                return R.drawable.ic_autoshape_line_big;
            case OVAL:
                return R.drawable.ic_autoshape_oval_big;
            case REGULAR_TRIANGLE:
                return R.drawable.ic_autoshape_triangle_big;
            case RIGHT_TRIANGLE:
                return R.drawable.ic_autoshape_triangle_2_big;
            case SQUARE:
                return R.drawable.ic_autoshape_square_big;
            case STAR:
                return R.drawable.ic_autoshape_star_big;
            default:
                return 0;
        }
    }

    public Autoshape create(Context context, float x, float y, float canvasRatio) {
        if (canvasRatio == 0 || Double.isNaN(canvasRatio) || Double.isNaN(canvasRatio) || Double.isInfinite(canvasRatio) || Double.isInfinite(canvasRatio)) {
            canvasRatio = 1;
        }
        Autoshape autoshape = new Autoshape(context, x, y, getType(), ContextCompat.getColor(context, getColorRes()), fill, canvasRatio);
        return autoshape;
    }

}
